import 'package:flutter/material.dart';
import 'package:flutter_app/MyPlugin.dart';
import 'package:flutter_yfree/YFree.dart';

class MyPage extends YPage {
  var title = "";

  @override
  void yOnCreate() {
    setState(() => title = yGetAppName());
    yShowBuilder("本项目仅可用于学习使用，非作者本人同意，请勿传播或用做任何商业用途。\n感谢您的支持！", () => showToast(), null, false);
    yBroadcast_register("broadcastKey", (params) => yToast(params!["msg"]));
  }

  Future<void> showToast() async {
    yBroadcast_send("broadcastKey", params: {"msg": await myPlugin.getMsg()});
  }

  @override
  Widget yBuild(BuildContext context) {
    return Scaffold(
      body: Container(
        color: Colors.white,
        child: Column(children: <Widget>[
          YAppBar(title: title, canBack: false),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                YButton(
                  child: Container(
                    width: 300,
                    height: 100,
                    alignment: Alignment.center,
                    child: Text("模拟广播", style: TextStyle(color: Colors.white, fontSize: 30, fontWeight: FontWeight.bold)),
                  ),
                  color: YConfig.themeColor,
                  onTap: () => showToast(),
                ),
                Container(height: 10),
                YButton(
                  child: Container(
                    width: 300,
                    height: 100,
                    alignment: Alignment.center,
                    child: Text("YFree_H5", style: TextStyle(color: Colors.white, fontSize: 30, fontWeight: FontWeight.bold)),
                  ),
                  color: YConfig.themeColor,
                  onTap: () => myPlugin.goH5(),
                ),
                Container(height: 10),
                YButton(
                  child: Container(
                    width: 300,
                    height: 100,
                    alignment: Alignment.center,
                    child: Text("YFree_Uniapp", style: TextStyle(color: Colors.white, fontSize: 30, fontWeight: FontWeight.bold)),
                  ),
                  color: YConfig.themeColor,
                  onTap: () => myPlugin.goUniapp("00A01"),
                ),
              ],
            ),
          ),
        ]),
      ),
    );
  }
}
